﻿using System;
using PoolGame2.Physics;
using PoolGame2.Player;

namespace PoolGame2.Rules
{
    class Ball8Rules : RuleC
    {
        PoolGame Game;

        public Ball8Rules(PoolGame game)
        {
            this.Game = game;
        }

        //No need to check 8Ball-ball collisions (only ones we care about are cue-ball)

        public override RulesEnum CheckRules(Ball ball)
        {
            int colours = 0;
            int stripes = 0;
            if (ball.getNumber() == 8 && ball.getPocketed())
            {
                PhysicsRuntime physicsRun = Game.gameManager.GetPhysicsRuntime();
                PlayerPresence playerPres = Game.gameManager.GetPlayerPresence();
                // Regardless of the outcome, it's going to be the other players turn (only one shot on black)
                playerPres.GameState.Active = false;
                // The only two legitimate occurances
                if (playerPres.getColours() && physicsRun.getColours() == 7)
                {
                    if (ball.getPocketed())
                    {
                        // Ball gone in, player wins!!
                        return RulesEnum.POT_WIN;
                    }
                }
                else if (playerPres.getStripes() && physicsRun.getStripes() == 7)
                {
                    if (ball.getPocketed())
                    {
                        // Ball gone in, player wins!!
                        return RulesEnum.POT_WIN;
                    }
                }
                else if (ball.getPocketed())
                {
                    // Blacks gone in, game over (unless we're on break)
                    return RulesEnum.POT_LOSE;
                }
            }

            return RulesEnum.ERROR;
        }
        public override RulesEnum CheckRules(Ball ball1, Ball ball2)
        {
            throw new NotImplementedException();
        }
    }
}
